package com.harmontronics.hanma.paas.paas.domain.iam.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.harmontronics.hanma.paas.paas.consts.NumberEnum;
import com.harmontronics.hanma.paas.paas.domain.iam.entity.GroupComponent;
import com.harmontronics.hanma.paas.paas.domain.iam.entity.HmUserGroupComponent;
import com.harmontronics.hanma.paas.paas.domain.iam.entity.valueobject.ComponentTypeEnum;
import com.harmontronics.hanma.paas.paas.domain.iam.entity.valueobject.HmUserGroupComponentFileds;
import com.harmontronics.hanma.paas.paas.domain.iam.repository.mapper.HmUserGroupComponentMapper;
import com.harmontronics.hanma.paas.paas.domain.iam.repository.persistence.HmBaseModuleComponentRepository;
import com.harmontronics.hanma.paas.paas.domain.iam.entity.HmBaseModuleComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.harmontronics.hanma.paas.paas.common.PageBase;

import com.harmontronics.hanma.paas.paas.domain.iam.repository.mapper.HmBaseModuleComponentMapper;
import com.harmontronics.hanma.paas.paas.domain.iam.repository.po.HmBaseModuleComponentPO;
import java.util.List;

@Service("hmBaseModuleComponentService")
@DS("#header.App-Unique")
public class HmBaseModuleComponentService {

    @Autowired
    private HmBaseModuleComponentRepository hmBaseModuleComponentRepository;


    public HmBaseModuleComponent findById( Long id) {
            HmBaseModuleComponentPO po = hmBaseModuleComponentRepository.getById(id);
        return BeanUtil.toBean(po,HmBaseModuleComponent. class);
    }

    public void save(HmBaseModuleComponent hmBaseModuleComponent) {
            HmBaseModuleComponentPO po = BeanUtil.toBean(hmBaseModuleComponent,HmBaseModuleComponentPO.class);
            hmBaseModuleComponentRepository.save(po);
    }

    public void update(HmBaseModuleComponent hmBaseModuleComponent) {
            HmBaseModuleComponentPO po = BeanUtil.toBean(hmBaseModuleComponent,HmBaseModuleComponentPO.class);
            hmBaseModuleComponentRepository.updateById(po);
    }

    public void remove(List<Long> ids) {
            hmBaseModuleComponentRepository.removeByIds(ids);
    }

    public List<HmBaseModuleComponent> getList() {
        List<HmBaseModuleComponentPO> pos = hmBaseModuleComponentRepository.list();
        return Convert.toList(HmBaseModuleComponent. class,pos);
    }

    public PageBase<HmBaseModuleComponent> getList(int pageNo, int pageSize,String type) {
        Page<HmBaseModuleComponentPO> page = new Page<>(pageNo, pageSize);
        QueryWrapper<HmBaseModuleComponentPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type", type);
        queryWrapper.orderByDesc("id");
        IPage<HmBaseModuleComponentPO> resultPage =
                    hmBaseModuleComponentRepository.selectPage(queryWrapper, page);
        return PageBase.from(resultPage,HmBaseModuleComponent. class);
    }




}